//
//  CourseCell.swift
//  Amicool
//
//  Created by Mac  on 2017/6/14.
//  Copyright © 2017年 Mac . All rights reserved.
//

import UIKit

class CourseCell: UITableViewCell {

    var title:UILabel = UILabel()
    var author:UILabel = UILabel()
    var updateTime:UILabel = UILabel()
    var img:UIImageView = UIImageView()
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        initialize()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init{code:) has not been implemented")
    }
    func initialize(){
        let shapeLayer = CAShapeLayer()
        shapeLayer.actions = ["positon":NSNull(),"bounds":NSNull(),"path":NSNull()]
        shapeLayer.shadowColor = UIColor.darkGray.cgColor
        shapeLayer.shadowOpacity = 0.6
        shapeLayer.shadowRadius = 4
        shapeLayer.shadowOffset = CGSize(width: 0, height: 3)
        shapeLayer.shadowPath = (UIBezierPath(roundedRect: CGRect(x:MARGIN,y:CELLHEIGHT/4,width:ScreenWidth-2*MARGIN,height:80), cornerRadius: 4)).cgPath
            
        shapeLayer.path = (UIBezierPath(roundedRect: CGRect(x:MARGIN,y:CELLHEIGHT/4,width:ScreenWidth-2*MARGIN,height:80), cornerRadius: 4)).cgPath
        shapeLayer.fillColor = UIColor.white.cgColor
        self.layer.insertSublayer(shapeLayer, at: 0)
        self.contentView.backgroundColor = UIColor.clear
        
        
        title.textAlignment = .left
        title.font = UIFont.systemFont(ofSize: 15)
        title.backgroundColor = UIColor.clear
        title.textColor = UIColor.black
        
        
        author.textAlignment = .left
        author.font = UIFont.systemFont(ofSize: 15)
        author.backgroundColor = UIColor.clear
        author.textColor = UIColor(red: 175/255, green: 186/255, blue: 202/255, alpha: 1)
        
        updateTime.textAlignment = .left
        updateTime.font = UIFont.systemFont(ofSize: 13)
        updateTime.textColor = UIColor.clear
        updateTime.textColor = UIColor(red: 175/255, green: 186/255, blue: 202/255, alpha: 1)
        
        img.layer.cornerRadius = 2
        img.layer.masksToBounds = true
        
        
        self.contentView.addSubview(title)
        self.contentView.addSubview(author)
        self.contentView.addSubview(updateTime)
        self.contentView.addSubview(img)
        
    }
    
    let ScreenWidth = UIScreen.main.bounds.size.width
    let ScreenHeight = UIScreen.main.bounds.size.height
    let CELLHEIGHT = CGFloat(100.0)
    let MARGIN = CGFloat(8.0)
    let WHRatio = CGFloat(4.0/3.0)
    
    
    override func layoutSubviews() {
    super.layoutSubviews()
    self.imageView?.frame = CGRect(x: MARGIN, y: CELLHEIGHT/4, width: WHRatio*CELLHEIGHT, height: 80)
        self.imageView?.layer.cornerRadius = 2
        self.imageView?.layer.masksToBounds = true
        
        self.img.frame = CGRect(x: MARGIN, y: CELLHEIGHT/4, width: WHRatio*CELLHEIGHT, height: 80)
        self.title.frame = CGRect(x: WHRatio*CELLHEIGHT+MARGIN*2, y: CELLHEIGHT/4, width: ScreenWidth-WHRatio*CELLHEIGHT+MARGIN-20, height: 20.0)
        self.author.frame = CGRect(x: WHRatio*CELLHEIGHT+MARGIN*2, y: CELLHEIGHT*2/4, width: ScreenWidth-WHRatio*CELLHEIGHT+MARGIN-20, height: 20.0)
        self.updateTime.frame = CGRect(x: WHRatio*CELLHEIGHT+MARGIN*2, y: CELLHEIGHT*3/4, width: ScreenWidth-WHRatio*CELLHEIGHT+MARGIN-20, height: 20.0)
        
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
